package StringBuilder.exercise;

import java.util.ArrayList;
import java.util.Scanner;

//集合里面有5个学生对象（案例3中得到的）   把其中 叫做"张无"的学生 改名为  "张五"  （注意是改名 不是把学生杀了并新建学生）
public class Demo5 {
    public static void main(String[] args) {
        ArrayList<unStudent> Array=new ArrayList<>();
        unStudent st1=stNew();
        unStudent st2=stNew();
        unStudent st3=stNew();
        unStudent st4=stNew();
        unStudent st5=stNew();
        Array.add(st1);
        Array.add(st2);
        Array.add(st3);
        Array.add(st4);
        Array.add(st5);
        for (int i = 0; i < Array.size(); i++) {
            unStudent ut=Array.get(i);
            System.out.println(ut.getName()+"  "+ut.getAge());
        }
        System.out.println("--------------------");
        for (int i = 0; i < Array.size(); i++) {
            unStudent unt=Array.get(i);
            if ("张无".equals(unt.getName())){
                unt.setName("张五");
            }
        }
        for (int i = 0; i < Array.size(); i++) {
            unStudent ut=Array.get(i);
            System.out.println(ut.getName()+"  "+ut.getAge());
        }
    }

    private static unStudent stNew() {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入学生姓名：");
        String name =sc.next();
        System.out.println("请输入学生年龄：");
        int age=sc.nextInt();
        return new unStudent(name,age);
    }
}
class unStudent{
    private String name;
    private int age;

    public unStudent() {
    }

    public unStudent(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
